package cn.tedu.attendance.controller;

import cn.tedu.attendance.pojo.vo.PageResult;
import cn.tedu.base.response.JsonResult;
import cn.tedu.attendance.pojo.entity.Attendance;
import cn.tedu.attendance.pojo.dto.AttendanceSaveParam;
import cn.tedu.attendance.pojo.dto.PageParam;
import cn.tedu.attendance.service.AttendanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/attendance")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;

    //查询所有出勤数据
    @GetMapping("list")
    public List<Attendance> findAll(){
        return attendanceService.findAll();
    }

    //查询单个出勤数据
    @GetMapping("select/{id}")
    public JsonResult findOne(@PathVariable("id")Integer id){
        Attendance attendance = attendanceService.findOne(id);
        return JsonResult.ok(attendance);
    }

    //删除出勤数据
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable("id")Integer id){
        attendanceService.delete(id);
        return JsonResult.ok();
    }

    //添加考勤数据
    @PostMapping("save")
    public JsonResult addOrUpdate(@RequestBody AttendanceSaveParam attendanceSaveParam){
        log.debug("保存用户,attendanceSaveParam={}",attendanceSaveParam);
        attendanceService.saveAttendance(attendanceSaveParam);
        return JsonResult.ok();
    }

    //分页查询
    @GetMapping("page")
    public PageResult<Attendance> pageQuery(PageParam param){
        return attendanceService.pageQuery(param) ;
    }


}
